package com.hydra.base.operate.log.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.hydra.base.entity.CodeEntity;
import com.hydra.base.error.BusinessException;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;

public class BaseOperateLogEntity extends CodeEntity {

    /**
     * 类型
     */
    @Getter @Setter
    private String cate;

    /**
     * 变更信息
     */
    @Getter @Setter
    private String info;

    /**
     * 操作类型
     */
    @Getter @Setter
    private String type;

    /**
     * 操作人账户名
     */
    @Getter @Setter
    private String operator;

    /**
     * 操作时间
     */
    @Getter @Setter
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private LocalDateTime operateTime;

    /**
     * 拷贝成一个新的对象
     */
    public <T extends BaseOperateLogEntity> T copy(Class<T> tClass){
        try {
            T data = tClass.newInstance();
            data.setCode(this.getCode());
            data.setCate(this.getCate());
            data.setType(this.getType());
            data.setInfo(this.getInfo());
            data.setOperator(this.getOperator());
            data.setOperateTime(this.getOperateTime());
            return data;
        } catch (Exception e) {
            throw new BusinessException(e.getMessage(), e);
        }
    }
}
